import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
} from 'typeorm';

/**
 * 性别枚举
 */
export enum Gender {
  MALE = 'male',
  FEMALE = 'female',
  OTHER = 'other',
}

/**
 * 用户实体
 */
@Entity('users')
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 50, unique: true, nullable: true, comment: '用户名' })
  username?: string;

  @Column({ length: 100, unique: true, nullable: true, comment: '邮箱' })
  email?: string;

  @Column({ length: 11, nullable: true, unique: true, comment: '手机号' })
  phone?: string;

  @Column({ name: 'md5password', length: 255, nullable: true, comment: '密码' })
  password?: string;

  // 微信相关字段
  @Column({ length: 100, nullable: true, unique: true, comment: '微信 openid' })
  openid?: string;

  @Column({
    length: 100,
    nullable: true,
    unique: true,
    comment: '微信 unionid',
  })
  unionid?: string;

  @Column({ length: 100, nullable: true, comment: '微信昵称' })
  nickname?: string;

  @Column({ default: true, comment: '是否激活' })
  isActive: boolean;

  // 个人信息
  @Column({ length: 500, nullable: true, comment: '头像URL' })
  avatar?: string;

  @Column({
    type: 'enum',
    enum: Gender,
    nullable: true,
    comment: '性别',
  })
  gender?: Gender;

  @Column({ type: 'date', nullable: true, comment: '生日' })
  birthday?: Date;

  @Column({ type: 'text', nullable: true, comment: '个人简介' })
  bio?: string;

  // 统计信息
  @Column({ default: 0, comment: '点赞数（用户点赞别人的总数）' })
  likesCount: number;

  @Column({ default: 0, comment: '获赞数（用户作品被点赞的总数）' })
  receivedLikesCount: number;

  @Column({ default: 0, comment: '关注数' })
  followingCount: number;

  @Column({ default: 0, comment: '粉丝数' })
  followersCount: number;

  @Column({ default: 0, comment: '收藏作品数' })
  collectionsCount: number;

  @Column({ default: 0, comment: '发布作品数' })
  worksCount: number;

  @CreateDateColumn({ type: 'timestamp', comment: '创建时间' })
  createdAt: Date;

  @UpdateDateColumn({ type: 'timestamp', comment: '更新时间' })
  updatedAt: Date;
}
